Skip to content

Add auto layout controls to node editor #8239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

skunkworxdark
Copy link
Contributor

Summary

Introduces auto layout functionality for the workflow editor using elkjs, including a new UI popover for layout options (placement strategy, layering, spacing, direction). Adds related state and actions to workflowSettingsSlice, updates translations, and ensures elkjs is included in dependencies.

If you select nodes, only those will have auto layout applied. Otherwise, all nodes in a workflow will be affected.

Related Issues / Discussions

NA

QA Instructions

Load a workflow and Auto Layout. With and without nodes selected.

Merge Plan

NA

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

Introduces auto layout functionality for the node editor using elkjs, including a new UI popover for layout options (placement strategy, layering, spacing, direction). Adds related state and actions to workflowSettingsSlice, updates translations, and ensures elkjs is included in optimized dependencies.
@github-actions github-actions bot added frontend-deps PRs that change frontend dependencies frontend PRs that change frontend files labels Jul 8, 2025
@skunkworxdark
Copy link
Contributor Author

skunkworxdark commented Jul 8, 2025

Here is a video showing the current operation:

workflow-autolayout.mp4

This is my first frontend change to invoke, and it was done heavily with the aid of Gemini. So be brutal in reviewing it, as I am sure I will have made glaring mistakes and poor coding style choices.

- The auto-layout settings panel is updated to use `Select` dropdowns and `NumberInput`
- The layout algorithm now uses the actual rendered dimensions of nodes from the DOM, falling back to estimates only when necessary. This results in a much more accurate and predictable layout.
- The ELKjs library integration is refactored to fix some warnings
@skunkworxdark
Copy link
Contributor Author

skunkworxdark commented Jul 11, 2025

  • Updated the auto layout settings to be dropdowns and added number picker to the sliders. look much neater.
  • Updated the node size detection to take from the rendered DOM. (not sure if there is a better way of doing this.
  • Refactored some imports to fix some warnings
workflow-autolayout2.mp4

@psychedelicious
Copy link
Collaborator

Will review and get this into v6.1.0

skunkworxdark and others added 4 commits July 17, 2025 14:37
- The auto-layout settings panel is updated to use `Select` dropdowns and `NumberInput`
- The layout algorithm now uses the actual rendered dimensions of nodes from the DOM, falling back to estimates only when necessary. This results in a much more accurate and predictable layout.
- The ELKjs library integration is refactored to fix some warnings
Copy link
Collaborator

@psychedelicious psychedelicious left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, works well! I cleaned up the importing of the library & left a couple minor comments.

One problem - the ElkJS library is 1.5 megabytes. That drastically increases the bundle size. Reviewing the library, it's an automated Javascript transpilation of the Elk library, which is written in Java.

I'm reluctant to add such a massive dependency. I noticed reactflow suggests d3-hierarchy as an alternative layout engine.

We currently use dagrejs to do auto-layouting when loading a workflow.

Can we use dagrejs or d3-hierarchy and provide a similar user experience without increasing the bundle size so much? I haven't explored the options these libraries provide.

Also, whichever direction we go in, we should only have a single graph lib dependency. We should mgirate the workflow loading logic to use whichever we choose.

@skunkworxdark
Copy link
Contributor Author

yikes, I hadn't realised the size of that package.

As I said previously, this was coded with a lot of help from Gemini, as I have very little React/TS experience. To be fair, I was surprised it worked as well as it did :)

I will take a look at your suggestions and see what I can come up with.

updated to use dagrejs - it has less layout options but is already included

but this is still WIP as some nodes don't report the height correctly. I am still investigating this...
@skunkworxdark
Copy link
Contributor Author

@psychedelicious

I think I have addressed all your previous points.

I updated to use dagrejs - it has less layout options then elkjs, but is already included, so no increase in bundle size.

However, this is still WIP (so still requires some cleanup) as some nodes don't report the height correctly and are squashed together after an auto layout. From what I can see so far, the nodes with the boolean toggles are reported as smaller, but they are not the only ones. It is late here now, so I will continue to look at this tomorrow.

If you can see anything I have done wrong or missed, please feel free to make suggestions.

@skunkworxdark skunkworxdark changed the title Add auto layout controls using elkjs to node editor Add auto layout controls to node editor Jul 18, 2025
update to fix layout issues
@skunkworxdark
Copy link
Contributor Author

@psychedelicious

It is ready for review again.

I found the issue and cleaned up the code.
FWIW: The issue was that the dagrejs library handles the nodes from the centres, whereas flow is the top left.

@skunkworxdark
Copy link
Contributor Author

workflow-autolayout3.mp4

- pretty useAutoLayout.ts
- add missing type import in ViewportControls.tsx
- update pnpm-lock.yaml with elkjs removed
Fix Frontend check -  remove unused export from workflowSettingsSlice.ts
Update so that if you have a single node selected, it will auto layout all nodes, as this is a common thing to have a single node selected and means that you don't have to unselect it.
@skunkworxdark
Copy link
Contributor Author

@psychedelicious

After a couple of minor fixes and a merge to main, it should be fully ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend PRs that change frontend files frontend-deps PRs that change frontend dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants